home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / ask2.arc / ASK2.ASM next >
Encoding:
Assembly Source File  |  1985-07-07  |  5.5 KB  |  189 lines

  1.     PAGE    64,132
  2. TITLE    ASK.COM        Set Error Level from keyboard for Batch file use.
  3. ;------------------------------------------------------------------------
  4. ;    Published in Programmers Journal Vol 3, No. 2 by Dan Rollins    ;
  5. ;    Modified for both IBM and Victor 9000 compatibility         ;
  6. ;                    by Guy Gordon 6/4/85        ;
  7. ;                                    ;
  8. ;    Batch file utility sets ERRORLEVEL according to user input    ;
  9. ;                                    ;
  10. ;    sytax:                                ;
  11. ;                                    ;
  12. ;    ASK prompt-string                        ;
  13. ;                                    ;
  14. ;    The prompt-string is displayed followed by 1 space, then the     ;
  15. ;    program pauses till a key is pressed.  If the key is acceptable ;
  16. ;    it is displayed, (followed by CR) and ERRORLEVEL is set.    ;
  17. ;    Otherwise a beep is sounded and the program continues to wait.    ;
  18. ;                                    ;
  19. ;        valid     |  returned                    ;
  20. ;       replies    | ERRORLEVEL                    ;
  21. ;    ------------------------                    ;
  22. ;    ESC           |    0                        ;
  23. ;    0  q  Q  F10  |    0                        ;
  24. ;    1  y  Y  F1   |    1                        ;
  25. ;    2  n  N  F2   |    2                        ;
  26. ;    3        F3   |    3                        ;
  27. ;    .        .    |    .                        ;
  28. ;    .        .    |    .                        ;
  29. ;    9        F9   |    9                        ;
  30. ;                                    ;
  31. ;    Example usage in a batch file:                    ;
  32. ;                                    ;
  33. ;        echo off                        ;
  34. ;        :start    BASCOM compile & link with optional re-edit    ;
  35. ;        bascom %1;                        ;
  36. ;        ask Re-edit source code (Y/N)?                ;
  37. ;        if errorlevel 2 goto continue                ;
  38. ;        rem     control falls through when user answers Y    ;
  39. ;        edlin %1.BAS                        ;
  40. ;        goto start                        ;
  41. ;        :continue   This branch taken when user answers N    ;
  42. ;        link %1;                        ;
  43. ;                                    ;
  44. ;------------------------------------------------------------------------
  45.  
  46. CODE    SEGMENT PARA
  47.     ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
  48.  
  49.     ORG    100H
  50. ASK    PROC    NEAR
  51.     JMP    START
  52.  
  53. ;------------------------------------------------------------------------
  54. ;    These tables have three bytes per element:            ;
  55. ;        1.  the ASCII input value                ;
  56. ;        2.  the exit code returned to DOS            ;
  57. ;        3.  the character to display                ;
  58. ;------------------------------------------------------------------------
  59. NORMAL_KEYS    LABEL    BYTE        ;non-extended ASCII table
  60.     DB    'Q',0,'Q', 'q',0,'Q',  27,0,'q'        ;last is Esc
  61.     DB    'Y',1,'Y', 'y',1,'Y', '1',1,'1'
  62.     DB    'N',2,'N', 'n',2,'N', '2',2,'2'
  63.     DB    '3',3,'3', '4',4,'4', '5',5,'5'
  64.     DB    '6',6,'6', '7',7,'7', '8',8,'8', '9',9,'9','0',0,'0'
  65.  
  66.     DB    0F1H,1,'1', 0F2H,2,'2', 0F3H,3,'3'     ;Victor fn keys
  67.     DB    0F4H,4,'4', 0F5H,5,'5', 0F6H,6,'6'
  68.     DB    0F7H,7,'7', 0F8H,8,'8', 0F9H,9,'9', 0FAH,0,'0'
  69.  
  70.     DB    0B1H,1,'1', 0B2H,2,'2', 0B3H,3,'3'     ;Victor fn keys
  71.     DB    0B4H,4,'4', 0B5H,5,'5', 0B6H,6,'6'
  72.     DB    0B7H,7,'7', 0B8H,8,'8', 0B9H,9,'9', 0BAH,0,'0'
  73.  
  74. NK_LEN    EQU    ($ - NORMAL_KEYS)/3    ;count of 3-byte elements in table
  75.  
  76. FN_KEYS        LABEL    BYTE        ;extended ASCII
  77.     DB    59,1,'1', 60,2,'2', 61,3,'3', 62,4,'4', 63,5,'5'  ;fn keys
  78.     DB    64,6,'6', 65,7,'7', 66,8,'8', 67,9,'9', 68,0,'0'
  79.  
  80.     DB    79,1,'1', 80,2,'2', 81,3,'3', 75,4,'4', 73,5,'5'  ;num pad
  81.     DB    77,6,'6', 71,7,'7', 72,8,'8', 73,9,'9', 82,0,'0'
  82.  
  83. FK_LEN    EQU    ($ - FN_KEYS)/3        ;count of 3-byte elements in table
  84.  
  85. BAD_VER_MSG    DB    'Wrong DOS version', 0Dh, 0Ah, '$'
  86.  
  87. ;------------------------------------------------------------------------
  88.  
  89. ;            CHECK IF DOS 2.X
  90.  
  91. START:    MOV    AH,30h            ;get DOS version number
  92.     INT    21h            ;
  93.     CMP    AL,2            ;at least version 2.0?
  94.     JAE    A10            ; yes, go
  95.     MOV    DX,OFFSET BAD_VER_MSG    ; no,
  96.     MOV    AH,9            ;  display message
  97.     INT    21h            ;    and
  98.     INT    20h            ;     exit
  99.  
  100. ;            DISPLAY PROMPT STRING
  101.  
  102. A10:    MOV    SI,80h            ;point to parameter string
  103.     MOV    CL,[SI]            ;get length
  104.     INC    SI            ;
  105.     MOV    CH,0            ;
  106.     ADD    SI,CX            ;find end of prompt string
  107.     MOV    BYTE PTR [SI],' '    ;add a space
  108.     MOV    BYTE PTR [SI+1],'$'    ;terminate string
  109.  
  110.     MOV    DX,82h            ;point to first character in string
  111.     MOV    AH,9            ;
  112.     INT    21h            ;
  113.  
  114. ;            GET KEY FROM KEYBOARD
  115.  
  116. AGAIN:                    ;re-entry point after unknown input
  117.     MOV    DI,OFFSET NORMAL_KEYS    ;assume non-extended (normal) key
  118.     MOV    CX,NK_LEN
  119.  
  120.     MOV    AH,7            ;
  121.     INT    21h            ;wait for a key
  122.     CMP    AL,0            ;extended ASCII?
  123.     JNE    A20            ;  no, skip
  124.     MOV    AH,7            ;  yes,
  125.     INT    21h            ;  fetch the scan code into AL
  126.     MOV    DI,OFFSET FN_KEYS    ;  and set up for extended ASCII table
  127.  
  128. A20:    SCASB                ;is AL in key table?
  129.     JZ    A30            ;  yes, we're done
  130.     INC    DI            ;  no, skip past return code in table
  131.     INC    DI            ;      and past display byte
  132.     LOOP    A20            ;      and try next elemetn
  133.  
  134.     CALL    BEEP            ;not found, so beep
  135.     JMP    AGAIN            ; and restart
  136.  
  137. ;            DISPLAY THE CHARACTER
  138.  
  139. A30:    MOV    DL,[DI+1]        ;it was found
  140.     MOV    AH,2            ;so display the character
  141.     INT    21h            ;
  142.  
  143.     CALL    CRLF            ;and linefeed carriage-return
  144.  
  145.     MOV    AL,[DI]            ;fetch the return code
  146.  
  147.     MOV    AH,4Ch            ;
  148.     INT    21h            ;return AL as error level
  149.  
  150. ASK    ENDP
  151.  
  152. ;------------------------------------------------------------------------
  153. ;    BEEP near procedure                        ;
  154. ;        sounds a beep by 'printing' an ASCII 7 (BEL character)    ;
  155. ;        all registers preserved                    ;
  156. ;------------------------------------------------------------------------
  157. BEEP    PROC    NEAR
  158.     PUSH    AX
  159.     PUSH    DX
  160.     MOV    AH,2
  161.     MOV    DL,7            ;BEL character
  162.     INT    21h
  163.     POP    DX
  164.     POP    AX
  165.     RET
  166. BEEP    ENDP
  167.  
  168. ;------------------------------------------------------------------------
  169. ;    CRLF near procedure                        ;
  170. ;        displays a linefeed and carriage-return            ;
  171. ;        all registers preserved                    ;
  172. ;------------------------------------------------------------------------
  173. CRLF    PROC    NEAR
  174.     PUSH    AX
  175.     PUSH    DX
  176.     MOV    AH,2
  177.     MOV    DL,0Dh            ;CR character
  178.     INT    21h
  179.     MOV    AH,2
  180.     MOV    DL,0Ah            ;LF character
  181.     INT    21h
  182.     POP    DX
  183.     POP    AX
  184.     RET
  185. CRLF    ENDP
  186.  
  187. CODE    ENDS
  188.     END    ASK